#!/bin/bash

make_link() {
    name="$2"
    source_file="$1"

    ln -fs "$source_file" "/etc/init.d/$name"
    ln -fs "/etc/init.d/$name" "/etc/rc0.d/K00$name"
    ln -fs "/etc/init.d/$name" "/etc/rc1.d/K00$name"
    ln -fs "/etc/init.d/$name" "/etc/rc2.d/S10$name"
    ln -fs "/etc/init.d/$name" "/etc/rc3.d/S10$name"
    ln -fs "/etc/init.d/$name" "/etc/rc4.d/S10$name"
    ln -fs "/etc/init.d/$name" "/etc/rc5.d/S10$name"
    ln -fs "/etc/init.d/$name" "/etc/rc6.d/K00$name"

    if [ "X$?"="X0" ]; then
        chmod 755 "/etc/init.d/$name"
    fi
}

arg="/`echo ${1#*/}`"

if [ ! -f "$arg" ]; then
   echo "The file doesn't exist!!"
   exit 1
fi

name=`echo ${arg##*/}`
make_link "$arg" "$name"

